<?php
namespace addons\qingdongams\controller;

use addons\qingdongams\model\Product;
use addons\qingdongams\model\Parts as PartsModel;
use think\Db;

class WebParts extends WebIndexApi
{

    public function __construct()
    {
        parent::__construct();
    }

    // 获取产品列表
    public function getProductList(){
        $name  = input('name');
        $where = [];
        if ($name) {
            $where['name'] = ['like', "%{$name}%"];
        }
        $list              = Product::where($where)->with(['createStaff'])->field('id,name,status')->select();
        $this->success('请求成功', $list);
    }

    // 获取配件列表
    public function getPartsList(){
        $limit = input("limit/d", 10);
        $params = $this->request->post();
        $where = $followWhere = [];
        $order = 'id desc';
        if (isset($params['name']) && $params['name']) {//配件名称
            $where['name'] = ['like', "%{$params['name']}%"];
        }
        if (isset($params['product_id']) && $params['product_id']) {//产品名称
            $product_id=intval($params['product_id']);
            $followWhere[] = ['exp', Db::raw('FIND_IN_SET(' .$product_id. ',product_id)')];
        }
        $list = PartsModel::where($where)->where($followWhere)->order($order)->paginate($limit);
        $this->success('请求成功', $list);
    }


}